package com.sds.servlet.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.sds.database.ibatis.sample.dao.BatchJobExecutionDAO;
import com.sds.database.ibatis.sample.vo.BatchJobExecutionVO;
import com.sds.servlet.vo.HeaderVO;

@Controller
public class FrameworkController {
	
	private Logger logger = LoggerFactory.getLogger(FrameworkController.class);
	
	@Resource
	private BatchJobExecutionDAO batchJobExecutionDAO;
	
	@ModelAttribute
	public HeaderVO headerVO(HttpServletRequest request, HttpServletResponse response) {
		HeaderVO headerVO = new HeaderVO();
		headerVO.setType("jsp");
		headerVO.setSessionId(request.getRequestedSessionId());
		return headerVO;
	}
	
	@RequestMapping("/test.do")
	public ModelAndView home(@ModelAttribute HeaderVO headerVO, HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView("jsp/test");
		logger.debug("type : " + headerVO.getType());
		logger.debug("sessionid : " + headerVO.getSessionId());
		List<BatchJobExecutionVO> batchJobExecutionList = batchJobExecutionDAO.getList();
		if(batchJobExecutionList!=null) {
			for(BatchJobExecutionVO batchJobExecution : batchJobExecutionList) {
				logger.debug("Query Result : " + batchJobExecution.getStatus());
			}
		}
		mav.addObject("headerVO", headerVO);
		mav.addObject("message", "Basic Test Page");
		return mav;
	}
	
}
